/*
Brick And Blast, a crossplatform breakout game.
 Copyright (C) 2008-2010 Julien CLEMENT (andematunum@gmail.com)
 
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 

*/

#include "Bumper.h"

/**
* file   Bumper.cpp
* date   Sam 2 jan 2010 20:05:43 CET
* brief  TODO
*/

bool
Bumper::
update () {
  if (bounce_) {
    double x = SDL_GetTicks() - bounce_start_;
    if (x > 800) {
      size_.r = size_init_;
      bounce_ = false;
    }
    else {
      /** The formula is:
        *
        * abs( A.sin( (x/speed) + PI/2 ) / (1 + x / attenuation ) )
        */
      double y =
        (double)BOUNCE_AMPLITUDE *
        sin(x / BOUNCE_SPEED + M_PI/2.) / (1. + x / BOUNCE_ATTENUATION);
      if (y < 0) {
        y  = -y;
      }
      size_.r = size_init_ + y;
    }
    calculate_next_pixel_rect();
    update_pixel_rect();
    return true;
  }
  return false;
}

